package com.cong.string;

import java.util.Arrays;

/**
 * @author cong
 * <p>
 * created on 2021/3/29 下午3:40
 */
public class ReverseLeftWords {
    public static void main(String[] args) {
        String s = "lrloseumgh";
        int k =6;
        reverseLeftWords3(s,k);
    }

    /**
     * 切片操作
     * @param s
     * @param k
     */
    private static void reverseLeftWords(String s, int k) {
        System.out.println(s.substring(k)+s.substring(0, k));
    }

    /**
     * 遍历
     * @param s
     * @param k
     */
    private static void reverseLeftWords2(String s, int k) {
        StringBuilder builder = new StringBuilder();
        for (int i = k; i < s.length(); i++) {
            builder.append(s.charAt(i));
        }
        for (int i = 0; i < k; i++) {
            builder.append(s.charAt(i));
        }
        System.out.println(builder.toString());
    }

    /**
     * 取余
     * @param s
     * @param k
     */
    private static void reverseLeftWords3(String s, int k) {
        StringBuilder builder = new StringBuilder();
        for (int i = k; i < s.length()+k; i++) {
            builder.append(s.charAt(i%s.length()));
        }
        System.out.println(builder.toString());
    }

}
